home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / Sources / FWCFMRes.cpp next >
Encoding:
Text File  |  1996-08-16  |  7.1 KB  |  248 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWCFMRes.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWCFMRES_H
  13. #include "FWCFMRes.h"
  14. #endif
  15.  
  16. #ifndef FWSTDDEF_H
  17. #include "FWStdDef.h"
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef FWRESOUR_H
  25. #include "FWResour.h"
  26. #endif
  27.  
  28. #ifndef FWFILES_H
  29. #include "FWFiles.h"
  30. #endif
  31.  
  32. #ifndef FWEXCEPT_H
  33. #include "FWExcept.h"
  34. #endif
  35.  
  36. #ifdef FW_BUILD_MAC
  37.  
  38.     #ifndef __ERRORS__
  39.     #include <Errors.h>
  40.     #endif
  41.     
  42.     #ifndef __RESOURCES__
  43.     #include <Resources.h>
  44.     #endif
  45.     
  46.     #ifndef __CODEFRAGMENTS__
  47.     #include <CodeFragments.h>
  48.     #endif
  49.  
  50.     #ifndef __FRAGRSRC__
  51.     #include <FragRsrc.h>
  52.     #endif
  53.  
  54. #endif
  55.  
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment fwresour
  58. #endif
  59.  
  60. //========================================================================================
  61. //    Global Variable
  62. //========================================================================================
  63. //    FW_gInstance is initialized in InitLibraryResources on the Mac
  64. //    FW_gInstance is defined in FWLbInit.cpp for Windows
  65.  
  66. #ifdef FW_BUILD_MAC
  67. FW_SCodeFragRefFile gNullCodeFrag = {NULL, -1, 0};
  68. FW_Instance FW_gInstance = &gNullCodeFrag;
  69. #endif
  70.  
  71. //========================================================================================
  72. //    Global functions
  73. //========================================================================================
  74.  
  75. //========================================================================================
  76. //    class FW_CAcquireCFMResourceAccess
  77. //========================================================================================
  78.  
  79. #ifdef FW_BUILD_MAC
  80. FW_DEFINE_AUTO(FW_CAcquireCFMResourceAccess)
  81. #endif
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess(Environment* ev)
  88. {
  89. #ifdef FW_BUILD_MAC
  90.     fInstance = FW_gInstance;
  91.     CommonInit(ev);
  92.     FW_END_CONSTRUCTOR
  93. #endif
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. // FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess
  98. //----------------------------------------------------------------------------------------
  99.  
  100. FW_CAcquireCFMResourceAccess::FW_CAcquireCFMResourceAccess(Environment* ev, FW_Instance instance)
  101. {
  102. #ifdef FW_BUILD_MAC
  103.     fInstance = instance;
  104.     CommonInit(ev);
  105.     FW_END_CONSTRUCTOR
  106. #endif
  107. }
  108.  
  109. #ifdef FW_BUILD_MAC
  110. //----------------------------------------------------------------------------------------
  111. // FW_CAcquireCFMResourceAccess::CommonInit
  112. //----------------------------------------------------------------------------------------
  113.  
  114. void FW_CAcquireCFMResourceAccess::CommonInit(Environment* ev)
  115. {
  116. FW_UNUSED(ev);
  117.     FW_ASSERT(fInstance != NULL);
  118.  
  119.     short ref = CurResFile();
  120.     
  121.     if(fInstance->fNesting > 0 )
  122.         ::UseResFile(fInstance->fRefNum);
  123.     else 
  124.     {
  125.         FW_FailOnError(::BeginCFragResources(fInstance->fFragRef));
  126.         fInstance->fRefNum = ::CurResFile();
  127.     }
  128.     fInstance->fNesting++;
  129.     fSavedLibraryRefNum = ref;
  130. }
  131. #endif
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess
  135. //----------------------------------------------------------------------------------------
  136.  
  137. FW_CAcquireCFMResourceAccess::~FW_CAcquireCFMResourceAccess()
  138. {
  139. #ifdef FW_BUILD_MAC
  140.     FW_START_DESTRUCTOR
  141.     
  142.     if(fInstance->fNesting > 0 )
  143.         if( --fInstance->fNesting == 0 )
  144.             FW_FailOnError(::EndCFragResources(fInstance->fFragRef));
  145.     ::UseResFile(fSavedLibraryRefNum);
  146. #endif
  147. }
  148.  
  149. #ifdef FW_BUILD_MAC
  150. //----------------------------------------------------------------------------------------
  151. // FW_CAcquireCFMResourceAccess::PrivInitLibraryResources
  152. //----------------------------------------------------------------------------------------
  153.  
  154. OSErr FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(CFragInitBlockPtr init)
  155. {
  156.     return InitCFragResources(init,&FW_gInstance->fFragRef);
  157. }
  158. #endif
  159.  
  160. #ifdef FW_BUILD_MAC
  161. //----------------------------------------------------------------------------------------
  162. // FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources()
  166. {
  167. #ifdef FW_DEBUG
  168.     FW_ASSERT(FW_gInstance->fNesting == 0);
  169. #endif
  170.     
  171.     OSErr err= ::TermCFragResources(FW_gInstance->fFragRef);
  172.     FW_ASSERT(err == noErr);
  173.     
  174.     FW_gInstance->fFragRef = NULL;
  175.     FW_gInstance->fRefNum = -1;
  176.     FW_gInstance->fNesting = 0;
  177. }
  178. #endif
  179.  
  180. //========================================================================================
  181. //    class FW_CSharedLibraryResourceFile
  182. //========================================================================================
  183.  
  184. FW_DEFINE_AUTO(FW_CSharedLibraryResourceFile)
  185.  
  186. //----------------------------------------------------------------------------------------
  187. // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile(Environment* ev):
  191.     FW_PResourceFile()
  192. #ifdef FW_BUILD_MAC
  193.     ,fAcquireCFMResourceAccess(ev, FW_gInstance)
  194. #endif
  195. {
  196.     CommonInit(ev, FW_gInstance);
  197.     FW_END_CONSTRUCTOR
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. // FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CSharedLibraryResourceFile::FW_CSharedLibraryResourceFile(Environment* ev, FW_Instance instance):
  205.     FW_PResourceFile()
  206. #ifdef FW_BUILD_MAC
  207.     ,fAcquireCFMResourceAccess(ev, instance)
  208. #endif
  209. {
  210.     CommonInit(ev, instance);
  211.     FW_END_CONSTRUCTOR
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // FW_CSharedLibraryResourceFile::CommonInit
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void FW_CSharedLibraryResourceFile::CommonInit(Environment* ev, FW_Instance instance)
  219. {    
  220. #if 0
  221.     #ifdef FW_BUILD_MAC
  222.         FW_PResourceFile resourceFile(new FW_CResourceFileRep(ev, fAcquireCFMResourceAccess.GetLibraryRefNum()));
  223.     #endif
  224.     #ifdef FW_BUILD_WIN
  225.         FW_PResourceFile resourceFile(new FW_CResourceFileRep(ev, instance));
  226.     #endif
  227.         SetRep(resourceFile);
  228. #else
  229.     #ifdef FW_BUILD_MAC
  230. FW_UNUSED(instance);
  231.         FW_PResourceFile rep(ev, fAcquireCFMResourceAccess.GetLibraryRefNum());
  232.     #endif
  233.     #ifdef FW_BUILD_WIN
  234.         FW_PResourceFile rep(ev, instance);
  235.     #endif
  236.         SetRep(ev, rep);
  237. #endif
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. // FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile
  242. //----------------------------------------------------------------------------------------
  243.  
  244. FW_CSharedLibraryResourceFile::~FW_CSharedLibraryResourceFile()
  245. {
  246.     FW_START_DESTRUCTOR
  247. }
  248.